// TypeScript file
class windowGroup extends egret.Sprite{
    private contentBg:egret.Sprite = new egret.Sprite();  
    private group: eui.Group;
    private label: eui.Label;
    private scrol: eui.Scroller;
    private W:number;
    private H:number;
    public constructor (w:number,h:number,Cont:any=null){
        super();
        this.W = w;
        this.H = h;
        this.addContent(Cont);        
    }
    public addContent(Cont:any){
        if(!Cont) return;
        if(this.contentBg.numChildren){
            this.contentBg.removeChild(this.contentBg.getChildAt(0));
        }
        this.contentBg.addChild(Cont);
        this.addGroup(); 
    }
    private addGroup(){        
        this.group = new eui.Group;
        this.addChild(this.group);
        this.group.addChild(this.contentBg);        
        //先添加背景
        this.label = new eui.Label;
        this.group.addChild(this.label);
        this.label.wordWrap = true;
        this.label.width = this.W;
        this.label.height = this.contentBg.height+55;
        this.label.text = "";
        this.label.size = 15;
        this.label.touchEnabled = false;
        this.scrol = new eui.Scroller;
        this.scrol.height = this.H;
        this.scrol.bounces = true;
        this.addChild(this.scrol);
        this.scrol.viewport = this.group;
        //x:116.5 y:276.80
        //this.scrol.x = 292-566;
        //this.scrol.y = 98;
       // this.scrol.scrollPolicyV= ScrollPolicy.AUTO;
       this.scrol.addEventListener(eui.UIEvent.CHANGE_END,this.groupMove,this);
       this.addEventListener(egret.Event.REMOVED_FROM_STAGE,this.remove,this);
  }
  public setScrollV(){
      this.group.scrollV = 0;
  }
  public updateData(){
      this.label.width = this.W;
      this.label.height = this.contentBg.height;
  }
  private groupMove(e:eui.UIEvent){
      if(this.group.scrollV>=(this.contentBg.height-510)){
          this.dispatchEventWith("down");
      }
     // console.log("Y:"+this.group.scrollV + " : "+this.contentBg.height+ " : "+this.label.height);
  }
  private remove(e:egret.Event){
      //console.log("Group:delete");
      this.scrol.removeEventListener(eui.UIEvent.CHANGE_END,this.groupMove,this);
      this.removeEventListener(egret.Event.REMOVED_FROM_STAGE,this.remove,this);
  }
}